Conditions | 1 |
Paths | 1 |
Total Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | /** |
||
15 | function sidebar(state, visibility, data, format, util) { |
||
16 | let ct = this; |
||
17 | ct.state = state; |
||
18 | ct.data = data; |
||
19 | ct.format = format; |
||
20 | ct.util = util; |
||
21 | |||
22 | // returns the elements selected plus empty string '' |
||
23 | // '' represents misc resources and it is always 'active' |
||
24 | ct.activeElements = function(player) { |
||
25 | let result = []; |
||
26 | for(let slot of player.element_slots) { |
||
27 | if(slot){ |
||
28 | result.push(slot.element); |
||
29 | } |
||
30 | } |
||
31 | result.push(''); |
||
32 | return result; |
||
33 | } |
||
34 | |||
35 | ct.visibleResources = function(element) { |
||
36 | return visibility.visible(data.resources, isResourceVisible, element); |
||
37 | }; |
||
38 | |||
39 | function isResourceVisible(name, currentElement) { |
||
40 | if (!state.player.resources[name].unlocked) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | // This is for global resources e.g. protons, which do not |
||
45 | // belong to any element |
||
46 | let elements = data.resources[name].elements; |
||
47 | if (Object.keys(elements).length === 0 && currentElement === '') { |
||
48 | return true; |
||
49 | } |
||
50 | |||
51 | for (let element in elements) { |
||
52 | if (currentElement === element) { |
||
53 | return true; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | return false; |
||
58 | } |
||
59 | } |
||
60 |